import { WebSocketServer } from "ws";
import { styleText } from "node:util";

const wss = new WebSocketServer({ port: 8080 });

wss.on("connection", function connection(ws) {
  ws.on("error", console.error);

  ws.on("message", function message(data) {
    console.log(data);
    console.log(data.type);
    console.log(data.toString("utf-8"));
    console.log(data.toString());
  });

  ws.send("Hello");
});

console.log(
  styleText("green", `Websocket server open succed in ${wss.options.port}`)
);
